<!DOCTYPE html>
<html lang=zh>
<head><meta name="generator" content="Hexo 3.9.0">
    <!-- so meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="HandheldFriendly" content="True">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="description" content="前言产品提了个需求希望能有个页面能将 word 文档一次性转换成可访问的线上地址，瞬间感觉压力山大，那就先从上传文件开始吧~其实靠上传我都实现过好多次了，但是过了不久又会忘记，然后又得各种百度去找答案，这里强制自己记录下。 新建 koa2 项目使用koa-generator可以通过命令行的方式初始化一个koa2项目 123npm install -g koa-generatorkoa2 xxxcd">
<meta name="keywords" content="同花顺,koa,nodejs">
<meta property="og:type" content="article">
<meta property="og:title" content="koa上传文件">
<meta property="og:url" content="https://andyliwr.github.io/2018/08/03/koa_upload_file/index.html">
<meta property="og:site_name" content="月光倾城的代码小屋">
<meta property="og:description" content="前言产品提了个需求希望能有个页面能将 word 文档一次性转换成可访问的线上地址，瞬间感觉压力山大，那就先从上传文件开始吧~其实靠上传我都实现过好多次了，但是过了不久又会忘记，然后又得各种百度去找答案，这里强制自己记录下。 新建 koa2 项目使用koa-generator可以通过命令行的方式初始化一个koa2项目 123npm install -g koa-generatorkoa2 xxxcd">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="https://file.lantingshucheng.com/1533290091381.png">
<meta property="og:image" content="https://file.lantingshucheng.com/1533290269096.png">
<meta property="og:image" content="https://file.lantingshucheng.com/1533292320020.png">
<meta property="og:updated_time" content="2020-01-15T06:30:09.116Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="koa上传文件">
<meta name="twitter:description" content="前言产品提了个需求希望能有个页面能将 word 文档一次性转换成可访问的线上地址，瞬间感觉压力山大，那就先从上传文件开始吧~其实靠上传我都实现过好多次了，但是过了不久又会忘记，然后又得各种百度去找答案，这里强制自己记录下。 新建 koa2 项目使用koa-generator可以通过命令行的方式初始化一个koa2项目 123npm install -g koa-generatorkoa2 xxxcd">
<meta name="twitter:image" content="https://file.lantingshucheng.com/1533290091381.png">
    
    
        
          
              <link rel="shortcut icon" href="/images/favicon.ico">
          
        
        
          
            <link rel="icon" type="image/png" href="/images/favicon-192x192.png" sizes="192x192">
          
        
        
          
            <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon.png">
          
        
    
    <!-- title -->
    <title>koa上传文件</title>
    <!-- styles -->
    <link rel="stylesheet" href="/css/style.css">
    <!-- persian styles -->
    
      <link rel="stylesheet" href="/css/rtl.css">
    
    <!-- rss -->
    
    
</head>

<body class="max-width mx-auto px3 ltr">
    
      <div id="header-post">
  <a id="menu-icon" href="#"><i class="fas fa-bars fa-lg"></i></a>
  <a id="menu-icon-tablet" href="#"><i class="fas fa-bars fa-lg"></i></a>
  <a id="top-icon-tablet" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');" style="display:none;"><i class="fas fa-chevron-up fa-lg"></i></a>
  <span id="menu">
    <span id="nav">
      <ul>
         
          <li><a href="/">首页</a></li>
         
          <li><a href="/archives/">归档</a></li>
         
          <li><a href="/search/">搜索</a></li>
         
          <li><a href="/tags/">标签</a></li>
         
          <li><a href="/others/">其他文章</a></li>
        
      </ul>
    </span>
    <br/>
    <span id="actions">
      <ul>
        
        <li><a class="icon" href="/2018/08/05/linux_file_permission/"><i class="fas fa-chevron-left" aria-hidden="true" onmouseover="$('#i-prev').toggle();" onmouseout="$('#i-prev').toggle();"></i></a></li>
        
        
        <li><a class="icon" href="/2018/06/14/css_generate_arrow/"><i class="fas fa-chevron-right" aria-hidden="true" onmouseover="$('#i-next').toggle();" onmouseout="$('#i-next').toggle();"></i></a></li>
        
        <li><a class="icon" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');"><i class="fas fa-chevron-up" aria-hidden="true" onmouseover="$('#i-top').toggle();" onmouseout="$('#i-top').toggle();"></i></a></li>
        <li><a class="icon" href="#"><i class="fas fa-share-alt" aria-hidden="true" onmouseover="$('#i-share').toggle();" onmouseout="$('#i-share').toggle();" onclick="$('#share').toggle();return false;"></i></a></li>
      </ul>
      <span id="i-prev" class="info" style="display:none;">上一篇</span>
      <span id="i-next" class="info" style="display:none;">下一篇</span>
      <span id="i-top" class="info" style="display:none;">返回顶部</span>
      <span id="i-share" class="info" style="display:none;">分享文章</span>
    </span>
    <br/>
    <div id="share" style="display: none">
      <ul>
  <li><a class="icon" href="http://www.facebook.com/sharer.php?u=https://andyliwr.github.io/2018/08/03/koa_upload_file/"><i class="fab fa-facebook " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://twitter.com/share?url=https://andyliwr.github.io/2018/08/03/koa_upload_file/&text=koa上传文件"><i class="fab fa-twitter " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.linkedin.com/shareArticle?url=https://andyliwr.github.io/2018/08/03/koa_upload_file/&title=koa上传文件"><i class="fab fa-linkedin " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://pinterest.com/pin/create/bookmarklet/?url=https://andyliwr.github.io/2018/08/03/koa_upload_file/&is_video=false&description=koa上传文件"><i class="fab fa-pinterest " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="mailto:?subject=koa上传文件&body=Check out this article: https://andyliwr.github.io/2018/08/03/koa_upload_file/"><i class="fas fa-envelope " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://getpocket.com/save?url=https://andyliwr.github.io/2018/08/03/koa_upload_file/&title=koa上传文件"><i class="fab fa-get-pocket " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://reddit.com/submit?url=https://andyliwr.github.io/2018/08/03/koa_upload_file/&title=koa上传文件"><i class="fab fa-reddit " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.stumbleupon.com/submit?url=https://andyliwr.github.io/2018/08/03/koa_upload_file/&title=koa上传文件"><i class="fab fa-stumbleupon " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://digg.com/submit?url=https://andyliwr.github.io/2018/08/03/koa_upload_file/&title=koa上传文件"><i class="fab fa-digg " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.tumblr.com/share/link?url=https://andyliwr.github.io/2018/08/03/koa_upload_file/&name=koa上传文件&description="><i class="fab fa-tumblr " aria-hidden="true"></i></a></li>
</ul>

    </div>
    <div id="toc">
      <ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#前言"><span class="toc-number">1.</span> <span class="toc-text">前言</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#新建-koa2-项目"><span class="toc-number">2.</span> <span class="toc-text">新建 koa2 项目</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#写上传文件的前端页面"><span class="toc-number">3.</span> <span class="toc-text">写上传文件的前端页面</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#监听上传按钮点击事件"><span class="toc-number">4.</span> <span class="toc-text">监听上传按钮点击事件</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#后端代码"><span class="toc-number">5.</span> <span class="toc-text">后端代码</span></a></li></ol>
    </div>
  </span>
</div>

    
    <div class="content index py4">
        
        <article class="post" itemscope itemtype="http://schema.org/BlogPosting">
  <header>
    
    <h1 class="posttitle" itemprop="name headline">
        koa上传文件
    </h1>



    <div class="meta">
      <span class="author" itemprop="author" itemscope itemtype="http://schema.org/Person">
        <span itemprop="name">月光倾城的代码小屋</span>
      </span>
      
    <div class="postdate">
        <time datetime="2018-08-03T17:28:15.000Z" itemprop="datePublished">2018-08-03</time>
    </div>


      

      
    <div class="article-tag">
        <i class="fas fa-tag"></i>
        <a class="tag-link" href="/tags/koa/">koa</a>, <a class="tag-link" href="/tags/nodejs/">nodejs</a>, <a class="tag-link" href="/tags/同花顺/">同花顺</a>
    </div>


    </div>
  </header>
  

  <div class="content" itemprop="articleBody">
    <h3 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h3><p>产品提了个需求希望能有个页面能将 word 文档一次性转换成可访问的线上地址，瞬间感觉压力山大，那就先从上传文件开始吧~<br>其实靠上传我都实现过好多次了，但是过了不久又会忘记，然后又得各种百度去找答案，这里强制自己记录下。</p>
<h3 id="新建-koa2-项目"><a href="#新建-koa2-项目" class="headerlink" title="新建 koa2 项目"></a>新建 koa2 项目</h3><p>使用<code>koa-generator</code>可以通过命令行的方式初始化一个<code>koa2</code>项目</p>
<figure class="highlight properties"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">npm</span> <span class="string">install -g koa-generator</span></span><br><span class="line"><span class="attr">koa2</span> <span class="string">xxx</span></span><br><span class="line"><span class="attr">cd</span> <span class="string">xxx &amp;&amp; npm install</span></span><br></pre></td></tr></table></figure>
<h3 id="写上传文件的前端页面"><a href="#写上传文件的前端页面" class="headerlink" title="写上传文件的前端页面"></a>写上传文件的前端页面</h3><p><code>koa2</code> 默认的模板引擎是<code>pug</code>，点击这里查看<a href="https://pugjs.org/zh-cn/api/getting-started.html" target="_blank" rel="noopener">pug 的基本用法</a>。<br>为了避免上传的时候自动刷新页面，提交表单就直接不适用 <code>form</code> 元素了，直接使用<code>div</code>，然后监听提交按钮的点击事件。<br>选择 <code>word</code> 文档可以通过 <code>input</code> 的 <code>accept</code> 属性来做限制，将其设置为<code>application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document</code>。</p>
<p>详细代码如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">div(class=&apos;form&apos;)</span><br><span class="line">  div(class=&apos;form-group&apos;)</span><br><span class="line">    input(type=&apos;file&apos;, id=&apos;file&apos;, name=&apos;file&apos;, accept=&apos;application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document&apos;)</span><br><span class="line">    button(id=&apos;submit&apos;) 开始转换</span><br><span class="line">script(type=&apos;text/javascript&apos;, src=&apos;//cdn.bootcss.com/jquery/3.3.1/jquery.min.js&apos;)</span><br><span class="line">script(type=&apos;text/javascript&apos;, src=&apos;/javascripts/index.js&apos;)</span><br></pre></td></tr></table></figure>
<p><img src="https://file.lantingshucheng.com/1533290091381.png" alt="上传页面"></p>
<h3 id="监听上传按钮点击事件"><a href="#监听上传按钮点击事件" class="headerlink" title="监听上传按钮点击事件"></a>监听上传按钮点击事件</h3><p>为了方便操作 dom，我直接使用 jquery 了。<br>提交文件的时候使用 <code>FormData</code> ，点击这里查看<a href="https://developer.mozilla.org/zh-CN/docs/Web/API/FormData/Using_FormData_Objects" target="_blank" rel="noopener"><code>FormData</code>的详细用法</a>。其实主要是新建一个 <code>FormData</code> 对象，使用 <code>append</code> 方法将 <code>input</code> 选择的文件装载进去，然后将其作为 <code>body</code> 内容发送到后端</p>
<p>详细代码如下：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line">$(<span class="built_in">document</span>).ready(<span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">  <span class="keyword">var</span> uploading = <span class="literal">false</span>;</span><br><span class="line">  $(<span class="string">'#submit'</span>).on(<span class="string">'click'</span>, <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="keyword">if</span> (uploading) &#123;</span><br><span class="line">      alert(<span class="string">'文件正在上传中，请稍候'</span>);</span><br><span class="line">      <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">var</span> file = <span class="keyword">new</span> FormData();</span><br><span class="line">    file.append(<span class="string">'file'</span>, $(<span class="string">'#file'</span>).prop(<span class="string">'files'</span>)[<span class="number">0</span>]);</span><br><span class="line">    $.ajax(&#123;</span><br><span class="line">      url: <span class="string">'/word-to-html'</span>,</span><br><span class="line">      type: <span class="string">'POST'</span>,</span><br><span class="line">      cache: <span class="literal">false</span>,</span><br><span class="line">      data: file,</span><br><span class="line">      processData: <span class="literal">false</span>,</span><br><span class="line">      contentType: <span class="literal">false</span>,</span><br><span class="line">      beforeSend: <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">        uploading = <span class="literal">true</span>;</span><br><span class="line">      &#125;,</span><br><span class="line">      success: <span class="function"><span class="keyword">function</span>(<span class="params">data</span>) </span>&#123;</span><br><span class="line">        <span class="comment">// 处理请求返回</span></span><br><span class="line">        uploading = <span class="literal">false</span>;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;);</span><br><span class="line">  &#125;);</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>
<p><img src="https://file.lantingshucheng.com/1533290269096.png" alt="console"></p>
<h3 id="后端代码"><a href="#后端代码" class="headerlink" title="后端代码"></a>后端代码</h3><p><code>koa</code> 需要借助中间件去处理传过来的 <code>body</code>，其实试过好多<code>koa-convert</code>、<code>koa-bodyparse</code>、<code>koa-better-body</code>，都遇到坑了。所以以后直接使用<code>koa-body</code>吧，简单关键有效。</p>
<p><strong> app.js </strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> body = <span class="built_in">require</span>(<span class="string">'koa-body'</span>);</span><br><span class="line"><span class="comment">// middlewares</span></span><br><span class="line">app.use(</span><br><span class="line">  body(&#123;</span><br><span class="line">    multipart: <span class="literal">true</span>,</span><br><span class="line">    urlencoded: <span class="literal">true</span></span><br><span class="line">  &#125;)</span><br><span class="line">);</span><br></pre></td></tr></table></figure>
<p><strong>routes/index.js</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">router.post(<span class="string">'/word-to-html'</span>, <span class="keyword">async</span> (ctx, next) =&gt; &#123;</span><br><span class="line">  <span class="built_in">console</span>.log(ctx.request.files);</span><br><span class="line">  ctx.body = <span class="string">'hello word'</span>;</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>
<p><img src="https://file.lantingshucheng.com/1533292320020.png" alt="后端接受参数"></p>

  </div>
  <div class="statement">
    <hr>  
    1. 如果本文帮到了您，不妨点一下右上角的”<i class="fas fa-share-alt"></i>“按钮。<br>
    2. 除非注明，本博文章均为原创，转载请以链接形式标明本文地址。<br>
    3. 如果你有任何疑问，欢迎发送邮件到我的邮箱<a href="mailto:andyliwr@outlook.com">andyliwr@outlook.com<br>
  </div>
</article>


    <div class="blog-post-comments">
        <div id="gitalk_thread">
            <noscript>加载评论需要在浏览器启用 JavaScript 脚本支持。</noscript>
        </div>
    </div>



        
          <div id="footer-post-container">
  <div id="footer-post">

    <div id="nav-footer" style="display: none">
      <ul>
         
          <li><a href="/">首页</a></li>
         
          <li><a href="/archives/">归档</a></li>
         
          <li><a href="/search/">搜索</a></li>
         
          <li><a href="/tags/">标签</a></li>
         
          <li><a href="/others/">其他文章</a></li>
        
      </ul>
    </div>

    <div id="toc-footer" style="display: none">
      <ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#前言"><span class="toc-number">1.</span> <span class="toc-text">前言</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#新建-koa2-项目"><span class="toc-number">2.</span> <span class="toc-text">新建 koa2 项目</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#写上传文件的前端页面"><span class="toc-number">3.</span> <span class="toc-text">写上传文件的前端页面</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#监听上传按钮点击事件"><span class="toc-number">4.</span> <span class="toc-text">监听上传按钮点击事件</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#后端代码"><span class="toc-number">5.</span> <span class="toc-text">后端代码</span></a></li></ol>
    </div>

    <div id="share-footer" style="display: none">
      <ul>
  <li><a class="icon" href="http://www.facebook.com/sharer.php?u=https://andyliwr.github.io/2018/08/03/koa_upload_file/"><i class="fab fa-facebook fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://twitter.com/share?url=https://andyliwr.github.io/2018/08/03/koa_upload_file/&text=koa上传文件"><i class="fab fa-twitter fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.linkedin.com/shareArticle?url=https://andyliwr.github.io/2018/08/03/koa_upload_file/&title=koa上传文件"><i class="fab fa-linkedin fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://pinterest.com/pin/create/bookmarklet/?url=https://andyliwr.github.io/2018/08/03/koa_upload_file/&is_video=false&description=koa上传文件"><i class="fab fa-pinterest fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="mailto:?subject=koa上传文件&body=Check out this article: https://andyliwr.github.io/2018/08/03/koa_upload_file/"><i class="fas fa-envelope fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://getpocket.com/save?url=https://andyliwr.github.io/2018/08/03/koa_upload_file/&title=koa上传文件"><i class="fab fa-get-pocket fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://reddit.com/submit?url=https://andyliwr.github.io/2018/08/03/koa_upload_file/&title=koa上传文件"><i class="fab fa-reddit fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.stumbleupon.com/submit?url=https://andyliwr.github.io/2018/08/03/koa_upload_file/&title=koa上传文件"><i class="fab fa-stumbleupon fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://digg.com/submit?url=https://andyliwr.github.io/2018/08/03/koa_upload_file/&title=koa上传文件"><i class="fab fa-digg fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.tumblr.com/share/link?url=https://andyliwr.github.io/2018/08/03/koa_upload_file/&name=koa上传文件&description="><i class="fab fa-tumblr fa-lg" aria-hidden="true"></i></a></li>
</ul>

    </div>

    <div id="actions-footer">
        <a id="menu" class="icon" href="#" onclick="$('#nav-footer').toggle();return false;"><i class="fas fa-bars fa-lg" aria-hidden="true"></i> 菜单</a>
        <a id="toc" class="icon" href="#" onclick="$('#toc-footer').toggle();return false;"><i class="fas fa-list fa-lg" aria-hidden="true"></i> 目录</a>
        <a id="share" class="icon" href="#" onclick="$('#share-footer').toggle();return false;"><i class="fas fa-share-alt fa-lg" aria-hidden="true"></i> 分享</a>
        <a id="top" style="display:none" class="icon" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');"><i class="fas fa-chevron-up fa-lg" aria-hidden="true"></i> 返回顶部</a>
    </div>

  </div>
</div>

        
        <footer id="footer">
  <div class="footer-left">
    Copyright &copy; 2020 Dikang Li
  </div>
  <div class="footer-right">
    <nav>
      <ul>
         
          <li><a href="/">首页</a></li>
         
          <li><a href="/archives/">归档</a></li>
         
          <li><a href="/search/">搜索</a></li>
         
          <li><a href="/tags/">标签</a></li>
         
          <li><a href="/others/">其他文章</a></li>
        
      </ul>
    </nav>
  </div>
</footer>

    </div>
</body>
</html>
<!-- styles -->
<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">
<link rel="stylesheet" href="/lib/justified-gallery/css/justifiedGallery.min.css">
<link rel="stylesheet" href="/lib/fancybox/jquery.fancybox.css">

<link rel="stylesheet" href="https://file.lantingshucheng.com/blog/v3/static/styles/gitalk.css">


<!-- jquery -->
<script src="/lib/jquery/jquery.min.js"></script>
<script src="/lib/justified-gallery/js/jquery.justifiedGallery.min.js"></script>
<script src="/lib/fancybox/jquery.fancybox.pack.js"></script>

<script type="text/javascript" src="https://file.lantingshucheng.com/blog/v3/static/scripts/md5.js"></script>
<script type="text/javascript" src="https://file.lantingshucheng.com/blog/v3/static/scripts/gitalk.min.js"></script>

<script src="/js/main.js"></script>
<!-- search -->

<!-- Google Analytics -->

<!-- Baidu Analytics -->

    <script type="text/javascript">
        var _hmt = _hmt || [];
        (function() {
            var hm = document.createElement("script");
            hm.src = "https://hm.baidu.com/hm.js?7851ca7a86be957be994acb77639a5be";
            var s = document.getElementsByTagName("script")[0];
            s.parentNode.insertBefore(hm, s);
        })();
    </script>

<!-- Disqus Comments -->


  <script type="text/javascript">
    window.onload = function(){
      if (window.location.href.indexOf('andyliwr.github.io') > -1) {
        var gitalk = new Gitalk({
          clientID: 'ad6f70df0c70d2b715f9',
          clientSecret: '40384bee244c1e17dd7c37733d21e9ef669e969c',
          repo: 'Andyliwr.github.io',
          owner: 'Andyliwr',
          admin: ['Andyliwr'],
          id: md5(location.pathname),
          distractionFreeMode: 'true'
        })
        gitalk.render('gitalk_thread')
      }
    }
  </script>


